/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.manager;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import ru.jSkyRoom.bridge.ModBridge;
import ru.jSkyRoom.interfaces.JSkyMod;
import skyproc.GRUP_TYPE;
import skyproc.Mod;
import skyproc.ModListing;
import skyproc.SPGlobal;
import skyproc.SPImporter;
import skyproc.exceptions.BadMod;
import skyproc.exceptions.BadRecord;
import skyproc.exceptions.MissingMaster;

/**
 *
 * @author Rakev
 */
public class ModExporter {

    private static ModExporter instance = new ModExporter();

    public static ModExporter getInstance() {
        return instance;
    }
    private String pathToSave;

    private ModExporter() {
    }

    public void exportMod(JSkyMod mod) throws IOException, BadRecord {
        if (mod instanceof ModBridge) {
            ((ModBridge) mod).getRawObject().export();
        } else {
            throw new IllegalArgumentException("Only bridge supported.");
        }
    }

    public void exportMod(JSkyMod mod, String path) throws IOException, BadRecord {
        if (mod instanceof ModBridge) {
            ((ModBridge) mod).getRawObject().export(path);
        } else {
            throw new IllegalArgumentException("Only bridge supported.");
        }
    }

    public String getPathToSave() {
        return pathToSave;
    }

    public void setPathToSave(String pathToSave) {
        this.pathToSave = pathToSave;
    }

    public void exportActiveMod() throws IOException, BadRecord {
        if (getModManager().getActiveMod() != null) {
            if (pathToSave != null) {
                ModExporter.getInstance().exportMod(getModManager().getActiveMod(), pathToSave);
            } else {
                ModExporter.getInstance().exportMod(getModManager().getActiveMod());
            }
        }
    }

    private ModManager getModManager() {
        return ModManager.getInstance();
    }
}
